﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>热表批次合卡撤销</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <div style="float: left;">
                    <div class="divLabel" style="margin-bottom: 5px">
                        批次名：</div>
                    <input id="txtContainerName" class="easyui-textbox" style="width: 150px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 10px">
                    <div class="divLabel" style="margin-bottom: 5px">
                        合卡名：</div>
                    <input id="txtCombinateName" class="easyui-textbox" style="width: 120px; height: 20px" />
                </div>
                <div style="float: left; margin-left: 20px">
                    <button id="btnSearch" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        width: 80px">
                        查询</button>
                    <button id="btnReset" class="easyui-linkbutton" data-options="" style="margin-top: 16px;
                        margin-left: 5px; width: 60px">
                        重置</button>
                </div>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="批次信息" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <table id="gdContainerInfo" class="easyui-datagrid" style="width: 100%; height: 150px"
                    data-options="rownumbers:true">
                </table>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="生产记录" style="padding: 3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 3px 0px 3px 3px">
                <div id="tt" class="easyui-tabs" style="width: 100%; height: 380px;">
                    <div title="派工记录" style="padding: 3px; display: none;">
                        <table id="gdDispatchInfo" class="easyui-datagrid" style="width: 100%; height: 300px"
                            data-options="rownumbers:true">
                        </table>
                        <div style="margin: 3px 0px 3px 3px" id="div1">
                            <button id="btnDeleteDispatch" class="easyui-linkbutton" type="button" style="width: 80px;
                                height: 26px;">
                                删除派工</button>
                        </div>
                    </div>
                    <div title="报工记录" data-options="" style="padding: 3px; display: none;">
                        <table id="gdWorkReportInfo" class="easyui-datagrid" style="width: 100%; height: 300px"
                            data-options="rownumbers:true">
                        </table>
                        <div style="margin: 3px 0px 3px 3px" id="div2">
                            <button id="btnDeleteWorkReport" class="easyui-linkbutton" type="button" style="width: 80px;
                                height: 26px;">
                                删除报工</button>
                        </div>
                    </div>
                    <div title="检验记录" data-options="" style="padding: 3px; display: none;">
                        <table id="gdCheckInfo" class="easyui-datagrid" style="width: 100%; height: 300px"
                            data-options="rownumbers:true">
                        </table>
                        <div style="margin: 3px 0px 3px 3px" id="div3">
                            <button id="btnDeleteCheck" class="easyui-linkbutton" type="button" style="width: 80px;
                                height: 26px;">
                                删除检验</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2023-06-28
    描述：热表批次的工步生产记录撤销页面js
    */
    var page = {
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/ContainerCombinateHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            page.initPage();
        },
        //页面事件绑定
        bind: function () {
            //批次列表加载
            $("#gdContainerInfo").datagrid({
                columns: [[
                 { field: 'MFGORDERNAME', title: '订单', width: 100 },
                 { field: 'CONTAINERNAME', title: '批次', width: 200 },
                 { field: 'PRODUCTNAME', title: '件号', width: 150 },
                 { field: 'WORKFLOWNAME', title: '工艺', width: 180 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'QTY', title: '在制数', width: 60 },
                 { field: 'CREATEDATE', title: '开卡日期', width: 80,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]]
            });
            //工步派工列表加载
            $("#gdDispatchInfo").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true, width: 30 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'STEPNO', title: '工步号', width: 80 },
                 { field: 'DESCRIPTION', title: '工步名', width: 110 },
                 { field: 'QTY', title: '派工数', width: 80 },
                 { field: 'FULLNAME', title: '派工人', width: 100 },
                 { field: 'CREATEDATE', title: '派工时间', width: 110,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]]
            });
            //工步报工列表加载
            $("#gdWorkReportInfo").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true, width: 30 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'STEPNO', title: '工步号', width: 80 },
                 { field: 'DESCRIPTION', title: '工步名', width: 110 },
                 { field: 'QTY', title: '报工数', width: 80 },
                 { field: 'FULLNAME', title: '报工人', width: 100 },
                 { field: 'CREATEDATE', title: '报工时间', width: 110,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 }
                ]]
            });
            //工步检验列表加载
            $("#gdCheckInfo").datagrid({
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true, width: 30 },
                 { field: 'WORKFLOWSTEPNAME', title: '工序', width: 150 },
                 { field: 'STEPNO', title: '工步号', width: 80 },
                 { field: 'DESCRIPTION', title: '工步名', width: 110 },
                 { field: 'CHECKQTY', title: '检验数', width: 80 },
                 { field: 'PASSQTY', title: '合格数', width: 80 },
                 { field: 'LOSSQTY', title: '报废数', width: 80 },
                 { field: 'FULLNAME', title: '检验人', width: 100 },
                 { field: 'CREATEDATE', title: '检验时间', width: 110,
                     formatter: function (value, row, index) {
                         if (!isNullOrWhiteSpaceStr(value)) {
                             return dayjs(value).format('YYYY-MM-DD');
                         }
                     }
                 },
                 { field: 'STEPSEQ', title: '顺序号', width: 80 }
                ]]
            });
            //查询按钮
             $('#btnSearch').on("click", function () {
                 clearEasyuiDataGrid("gdContainerInfo"); //清空列表
                 clearEasyuiDataGrid("gdDispatchInfo"); //清空列表
                 clearEasyuiDataGrid("gdWorkReportInfo"); //清空列表
                 clearEasyuiDataGrid("gdCheckInfo"); //清空列表
                page.search();
            });

            //清除按钮
            $('#btnReset').on("click", function () {
                $("#txtContainerName").textbox("setValue", ""); //批次名
                $("#txtCombinateName").textbox("setValue", ""); //合卡名
                clearEasyuiDataGrid("gdContainerInfo"); //清空列表
                clearEasyuiDataGrid("gdDispatchInfo"); //清空列表
                clearEasyuiDataGrid("gdWorkReportInfo"); //清空列表
                clearEasyuiDataGrid("gdCheckInfo"); //清空列表
            });
            //删除派工
            $('#btnDeleteDispatch').on("click", function () {
                page.deleDispatch();
            });
            //删除报工
            $('#btnDeleteWorkReport').on("click", function () {
                page.deleWorkReport();
            });
            //删除检验
            $('#btnDeleteCheck').on("click", function () {
                page.deleCheck();
            });
        },
        initPage: function () {
            $('#tt').tabs('disableTab', 0);
            $('#tt').tabs('disableTab', 1);
            $('#tt').tabs('disableTab', 2);
            page.post(page.url, { action: "InitRBCombinateContainerCancel" }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('disable');
                    });
                } else {
                    var data = JSON.parse(res.ReturnData);
                    for (var i = 0; i < data.length; i++) {
                        $('#tt').tabs('enableTab', data[i].showTab);
                    }
                    $('#tt').tabs('select', data[0].showTab);
                }
            });
        },
        //查询
        search: function () {
            var formData = {
                action: "GetRBContainerCancelDetailList",
                containerName: $("#txtContainerName").textbox("getValue"),
                combinateName: $("#txtCombinateName").textbox("getValue")
            };
            page.post(page.url, formData, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                $("#gdContainerInfo").datagrid('loadData', { rows: res.DBDataSet.dtContainer }); //批次信息
                $("#gdDispatchInfo").datagrid('loadData', { rows: res.DBDataSet.dtDispatch }); //派工信息
                $("#gdWorkReportInfo").datagrid('loadData', { rows: res.DBDataSet.dtWorkReport }); //报工信息
                $("#gdCheckInfo").datagrid('loadData', { rows: res.DBDataSet.dtCheck }); //检验信息
            });
        },
        //保存
        save: function () {
            var selected = $("#gdContainerInfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("未选择数据", false);
                return false;
            }
            var formData = {
                action: "SaveContainerCombinateData",
                container: JSON.stringify(selected)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //删除派工
        deleDispatch: function () {
            var container = $("#gdContainerInfo").datagrid("getRows");
            if (container.length === 0) {
                displayMessage("没有批次信息", false);
                return false;
            }
            var selected = $("#gdDispatchInfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("未选择数据", false);
                return false;
            }
            var formData = {
                action: "SaveStepInfoDispatchCancel",
                container: JSON.stringify(container),
                param: JSON.stringify(selected)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //删除报工
        deleWorkReport: function () {
            var container = $("#gdContainerInfo").datagrid("getRows");
            if (container.length === 0) {
                displayMessage("没有批次信息", false);
                return false;
            }
            var selected = $("#gdWorkReportInfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("未选择数据", false);
                return false;
            }
            var formData = {
                action: "SaveStepInfoWorkReportCancel",
                container: JSON.stringify(container),
                param: JSON.stringify(selected)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //删除检验
        deleCheck: function () {
            var container = $("#gdContainerInfo").datagrid("getRows");
            if (container.length === 0) {
                displayMessage("没有批次信息", false);
                return false;
            }
            var selected = $("#gdCheckInfo").datagrid("getChecked");
            if (selected.length === 0) {
                displayMessage("未选择数据", false);
                return false;
            }
            var formData = {
                action: "SaveStepInfoCheckCancel",
                container: JSON.stringify(container),
                check: JSON.stringify(selected)
            };
            page.post(page.url, formData, true, function (res) {
                if (res.Result) {
                    page.search();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
